package com.itehima.text;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Demo01 {

    public static void main(String[] args) {

    //  定义一个集合并添加一些数据
    //过滤奇数，只留下偶数
    //进行判断，如果是偶数，返回true
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);

        //实现过滤
        List<Integer> newlist = list.stream().filter(n -> n % 2 == 0).collect(Collectors.toList());
        System.out.println(newlist);//[2, 4, 6, 8, 10]

    }
}
